﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
using aoprinter.Tool;

namespace aoprinter.Draw
{
    class DoubleLineOper : ILineTypeOper
    {
        const string INTER_SIZE = "interSize";
        public GraphicsPath DrawLine(PointF point1, PointF point2, Dictionary<string, string> parameters)
        {
            float interSize = 1;
            if (parameters.ContainsKey(INTER_SIZE))
            {
                float.TryParse(parameters[INTER_SIZE], out interSize);
            }
            GraphicsPath path = new GraphicsPath();
            path.AddLine(point1, point2);
            path.StartFigure();
            PointF[] points = GeometryTool.ParallelLine(point1, point2, interSize);
            if (points.Length == 2 && !points[0].IsEmpty && !points[1].IsEmpty)
            {
                path.AddLine(points[0], points[1]);
            }
            return path;
        }

        public GraphicsPath DrawRect(RectangleF rect, Dictionary<string, string> parameters)
        {
            float interSize = 1;
            if (parameters.ContainsKey(INTER_SIZE))
            {
                float.TryParse(parameters[INTER_SIZE], out interSize);
            }
            GraphicsPath path = new GraphicsPath();
            path.AddRectangle(rect);
            path.AddRectangle(new RectangleF(rect.Location.X + interSize, rect.Location.Y + interSize,
                rect.Width - 2 * interSize, rect.Height - 2 * interSize));
            return path;
        }
    }
}
